#import "FlutterObsPlugin.h"
#import "OBSManager.h"
#import "StreamHandler.h"
@interface FlutterObsPlugin()

@property (nonatomic, strong) StreamHandler *streamHandler;

@end

@implementation FlutterObsPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  FlutterMethodChannel* channel = [FlutterMethodChannel
      methodChannelWithName:@"com.obs.navigator"
            binaryMessenger:[registrar messenger]];
    
  FlutterObsPlugin* instance = [[FlutterObsPlugin alloc] initWithrRgistrar:registrar];
    
  [registrar addMethodCallDelegate:instance channel:channel];

}

- (instancetype)initWithrRgistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
    if (self = [super init]) {
        _streamHandler = [[StreamHandler alloc] init];
        FlutterEventChannel *event = [FlutterEventChannel eventChannelWithName:@"com.obs/eventChannel" binaryMessenger:[registrar messenger]];
        [event setStreamHandler:_streamHandler];
    }
    return self;
}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
  if ([@"getPlatformVersion" isEqualToString:call.method]) {
    result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
  } else if ([@"startUpload" isEqualToString:call.method]) {
      NSArray *array = call.arguments[@"files"];
      for (NSDictionary *params in array) {
          [OBSManager uploadFileWithParams:params result:result handler:self.streamHandler];
      }
  } else {
    result(FlutterMethodNotImplemented);
  }
}

@end
